package com.gxa.autoparts.admin.controller;

import com.gxa.autoparts.admin.service.AfterSaleService;
import com.gxa.autoparts.admin.service.OrderService;
import com.gxa.autoparts.core.common.ExceptionCode;
import com.gxa.autoparts.core.common.JsonResult;
import com.gxa.autoparts.core.exception.BusinessException;
import com.gxa.autoparts.core.pojo.AfterSale;
import com.gxa.autoparts.core.pojo.Order;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("/afterSale")
@RestController
public class AfterSaleController {

    @Autowired
    AfterSaleService afterSaleService;




    @ApiOperation("退款单全查询")
    @PostMapping("/afterSale")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true),
            @ApiImplicitParam(name = "size", value = "每页记录数", required = true)
    })
    public Map afterSale(Integer page,Integer size){
        List<Map> maps = afterSaleService.afterSale(page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(maps);
        return jsonResult.getDataMap();
    }

    @ApiOperation("退款单模糊查询")
    @PostMapping("/afterSaleByLike")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sid", value = "订单号",dataType = "String",paramType = "query", required = false),
            @ApiImplicitParam(name = "name", value = "用户姓名",dataType = "String",paramType = "query", required = false),
            @ApiImplicitParam(name = "phone", value = "手机号",dataType = "String",paramType = "query", required = false),
            @ApiImplicitParam(name = "page", value = "页码", required = true),
            @ApiImplicitParam(name = "size", value = "每页记录数", required = true)
    })
    public Map afterSaleByLike(String sid,String name,String phone,Integer page,Integer size){
        List<Map> maps = afterSaleService.afterSaleByLike(sid, name, phone, page, size);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(maps);
        return jsonResult.getDataMap();
    }

    @ApiOperation("退款单同意（将全查询的aid传给后端）,同意的state为2，拒绝的state为3")
    @PostMapping("/updateState")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "aid", value = "退款id",dataType = "Long",paramType = "query", required = true),
            @ApiImplicitParam(name = "state", value = "状态号",dataType = "Integer",paramType = "query", required = true),
            @ApiImplicitParam(name = "remark", value = "拒绝原因",dataType = "String",paramType = "query", required = false)
    })
    public Map updateState(Long aid,Integer state,String remark){
        AfterSale afterSale = new AfterSale();
        afterSale.setId(aid);
        afterSale.setState(state);
        if (state == 3){
            afterSale.setReason(remark);
        }
        Integer integer = afterSaleService.updateById(afterSale);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        return jsonResult.getDataMap();
    }


}
